package com.example.demo.runner;

import com.example.demo.properties.AddressProps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@Order(value = 1)
public class AddressRunner implements ApplicationRunner {

    @Autowired
    private AddressProps props;


    @Override
    public void run(ApplicationArguments args) throws Exception {


        // 中文乱码未修改成功
        String province = props.getProvince();
        province = new String(province.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);

        String city = props.getCity();
        // city = new String(city.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);

        String county = props.getCounty();
        // county = new String(county.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);

        System.out.println("自定义配置文件address.properties文件信息如下:");

        System.out.println("province:" + province + ",city:" + city + ",county:" + county);

    }
}
